

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "PPNetworkCache.h"

#ifndef kIsNetwork
#define kIsNetwork     [PPNetworkHelper isNetwork]
#endif

#ifndef kIsWWANNetwork
#define kIsWWANNetwork [PPNetworkHelper isWWANNetwork]
#endif

#ifndef kIsWiFiNetwork
#define kIsWiFiNetwork [PPNetworkHelper isWiFiNetwork]  
#endif

typedef NS_ENUM(NSUInteger, PPNetworkStatusType) {
    PPNetworkStatusUnknown,
    PPNetworkStatusNotReachable,
    PPNetworkStatusReachableViaWWAN,
    PPNetworkStatusReachableViaWiFi
};

typedef NS_ENUM(NSUInteger, PPRequestSerializer) {
    PPRequestSerializerJSON,
    PPRequestSerializerHTTP,
};

typedef NS_ENUM(NSUInteger, PPResponseSerializer) {
    PPResponseSerializerJSON,
    PPResponseSerializerHTTP,
};


typedef void(^HttpRequestCallBack)(BOOL success,id responseObject,NSError *error);

typedef void(^PPHttpRequestSuccess)(id responseObject);

typedef void(^PPHttpRequestFailed)(NSError *error);

typedef void(^PPHttpRequestCache)(id responseCache);

typedef void (^PPHttpProgress)(NSProgress *progress);

typedef void(^PPNetworkStatus)(PPNetworkStatusType status);

@class AFHTTPSessionManager;
@interface PPNetworkHelper : NSObject


+ (BOOL)isNetwork;


+ (BOOL)isWWANNetwork;


+ (BOOL)isWiFiNetwork;


+ (void)cancelAllRequest;


+ (void)networkStatusWithBlock:(PPNetworkStatus)networkStatus;


+ (void)cancelRequestWithURL:(NSString *)URL;

+ (void)openLog;


+ (void)closeLog;


+(void)openAES;

+(void)closeAES;


+ (__kindof NSURLSessionTask *)GET:(NSString *)URL
                        parameters:(id)parameters
                           success:(PPHttpRequestSuccess)success
                           failure:(PPHttpRequestFailed)failure;


+ (__kindof NSURLSessionTask *)GET:(NSString *)URL
                        parameters:(id)parameters
                     responseCache:(PPHttpRequestCache)responseCache
                           success:(PPHttpRequestSuccess)success
                           failure:(PPHttpRequestFailed)failure;


+ (__kindof NSURLSessionTask *)POST:(NSString *)URL
                         parameters:(id)parameters
                            success:(PPHttpRequestSuccess)success
                            failure:(PPHttpRequestFailed)failure;


+ (__kindof NSURLSessionTask *)POST:(NSString *)URL
                         parameters:(id)parameters
                      responseCache:(PPHttpRequestCache)responseCache
                            success:(PPHttpRequestSuccess)success
                            failure:(PPHttpRequestFailed)failure;


+ (__kindof NSURLSessionTask *)uploadFileWithURL:(NSString *)URL
                                      parameters:(id)parameters
                                            name:(NSString *)name
                                        filePath:(NSString *)filePath
                                        progress:(PPHttpProgress)progress
                                         success:(PPHttpRequestSuccess)success
                                         failure:(PPHttpRequestFailed)failure;


+ (__kindof NSURLSessionTask *)uploadImagesWithURL:(NSString *)URL
                                        parameters:(id)parameters
                                              name:(NSString *)name
                                            images:(NSArray<UIImage *> *)images
                                         fileNames:(NSArray<NSString *> *)fileNames
                                        imageScale:(CGFloat)imageScale
                                         imageType:(NSString *)imageType
                                          progress:(PPHttpProgress)progress
                                           success:(PPHttpRequestSuccess)success
                                           failure:(PPHttpRequestFailed)failure;


+ (__kindof NSURLSessionTask *)downloadWithURL:(NSString *)URL
                                       fileDir:(NSString *)fileDir
                                      progress:(PPHttpProgress)progress
                                       success:(void(^)(NSString *filePath))success
                                       failure:(PPHttpRequestFailed)failure;




#pragma mark - 设置AFHTTPSessionManager相关属性
#pragma mark 注意: 因为全局只有一个AFHTTPSessionManager实例,所以以下设置方式全局生效

+ (void)setAFHTTPSessionManagerProperty:(void(^)(AFHTTPSessionManager *sessionManager))sessionManager;


+ (void)setRequestSerializer:(PPRequestSerializer)requestSerializer;


+ (void)setResponseSerializer:(PPResponseSerializer)responseSerializer;


+ (void)setRequestTimeoutInterval:(NSTimeInterval)time;


+ (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field;


+ (void)openNetworkActivityIndicator:(BOOL)open;


+ (void)setSecurityPolicyWithCerPath:(NSString *)cerPath validatesDomainName:(BOOL)validatesDomainName;

@end

